$(function () {
    var menuUrl = "/oa/t-menu";
    var token = sessionStorage.getItem('token');
    var oprateFormatter = function (value, row, index) {
        return [
            '<button id="tb_edit" class="btn btn-default btn-xs" style="margin: 0 5px 0 5px">编辑</button>',
            '<button id="tb_delete" class="btn btn-default btn-xs" style="margin: 0 5px 0 5px">删除</button>',
        ].join("");
    };

    var oprateEvents = function(context) {
        var me = context;
        return {
            "click #tb_edit" : function(e, value, row, index) {
                me.edit([row]);
            },

            "click #tb_delete" : function(e, value, row, index) {
                me.remove([row]);
            },
        };
    };

    var page = $.fn.cookePageTable({
        URL: menuUrl,
        dialog: {
            domid: '#addModel',
            title: '车辆',
            validate : {
                menuName: {
                    required: true,
                },
                menuAddr: {
                    required: true,
                },
            },
        },

        toolbar: {
            add: '#add',
            del: '#del',
            edit: '#edit',
            domid: '#toolbar',
            search: '#search',
        },

        table: {
            domid: "#table",
            uniqueId: "menuId", //每一行的唯一标识，一般为主键列
            uniqdesc: function(row) {
                return row.menuId;
            },                  //每一行的唯一标识描述字段信息
            columns: [{
                checkbox: true
            }, {
                field: 'menuId',
                title: '菜单编号',
                filter: true,
            }, {
                field: 'menuName',
                title: '菜单名称',
                filter: true,
            }, {
                field: 'menuAddr',
                title: '菜单地址',
                filter: true,
            }, {
                field: 'operate',
                title: '操作',
                visible: true,
                events: oprateEvents,
                formatter: oprateFormatter,
            }]
        },
    });
});
